﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ClaimData", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(ClaimData))]
    public class ClaimDataSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IClaimData clazz;
        
        public ClaimDataSerializer(IClaimData clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (((clazz.PrincipalClaim == null) 
                        || (clazz.PrincipalClaim.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "PrincipalClaim");
            }
            for (int x = 0; ((clazz.PrincipalClaim != null) 
                        && (x < clazz.PrincipalClaim.Count)); x = (x + 1)) {
                Writer.WriteStartElement("PrincipalClaim");
                if (clazz.PrincipalClaim[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaPrincipalClaim = this.GetMetaData(clazz.PrincipalClaim[x]);
                    Writer.WriteTypeAttribute(metaPrincipalClaim.TypeQualifiedName.Namespace, metaPrincipalClaim.TypeQualifiedName.Name);
                    metaPrincipalClaim.NewSerializer(clazz.PrincipalClaim[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PrincipalClaim");
                }
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("ClaimTotal");
            if (clazz.ClaimTotal!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "Sum");
                Writer.WriteString(clazz.ClaimTotal.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ClaimTotal");
            }
            Writer.WriteEndElement();
            if (((clazz.ClaimBase == null) 
                        || (clazz.ClaimBase.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "ClaimBase");
            }
            for (int x = 0; ((clazz.ClaimBase != null) 
                        && (x < clazz.ClaimBase.Count)); x = (x + 1)) {
                Writer.WriteStartElement("ClaimBase");
                if (clazz.ClaimBase[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaClaimBase = this.GetMetaData(clazz.ClaimBase[x]);
                    Writer.WriteTypeAttribute(metaClaimBase.TypeQualifiedName.Namespace, metaClaimBase.TypeQualifiedName.Name);
                    metaClaimBase.NewSerializer(clazz.ClaimBase[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ClaimBase");
                }
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("PrincipalClaimsTotal");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.PrincipalClaimsTotal))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("CollateralClaimsTotal");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "decimal");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDecimal(((decimal)(clazz.CollateralClaimsTotal))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("CircumstancesDescription");
            if (clazz.CircumstancesDescription!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "Description");
                Writer.WriteString(clazz.CircumstancesDescription.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : CircumstancesDescription");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Currency");
            if (clazz.Currency!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "Currency");
                Writer.WriteString(clazz.Currency.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Currency");
            }
            Writer.WriteEndElement();
            for (int x = 0; ((clazz.ClaimBaseClaim != null) 
                        && (x < clazz.ClaimBaseClaim.Count)); x = (x + 1)) {
                if (clazz.ClaimBaseClaim[x]!=null) {
                    Writer.WriteStartElement("ClaimBase_Claim");
                    global::Xtee.Core.SerializationMetadata metaClaimBaseClaim = this.GetMetaData(clazz.ClaimBaseClaim[x]);
                    Writer.WriteTypeAttribute(metaClaimBaseClaim.TypeQualifiedName.Namespace, metaClaimBaseClaim.TypeQualifiedName.Name);
                    metaClaimBaseClaim.NewSerializer(clazz.ClaimBaseClaim[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            clazz.PrincipalClaim = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPrincipalClaim>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "PrincipalClaim")); ) {
                if (Reader.LocalName=="PrincipalClaim") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>PrincipalClaim");
                    }
                    global::Xtee.Core.SerializationMetadata metaPrincipalClaim = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPrincipalClaim>(Reader, "PrincipalClaim", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPrincipalClaim item = metaPrincipalClaim.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPrincipalClaim>();
                    clazz.PrincipalClaim.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("PrincipalClaim");
                        metaPrincipalClaim.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>PrincipalClaim", Reader.LocalName);
                }
            }
            if ((clazz.PrincipalClaim.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "PrincipalClaim");
            }
            if (Reader.LocalName=="ClaimTotal") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>ClaimTotal");
                }
                clazz.ClaimTotal = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Sum(Reader.ReadElementString("ClaimTotal"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>ClaimTotal", Reader.LocalName);
            }
            clazz.ClaimBase = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaimData>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "ClaimBase")); ) {
                if (Reader.LocalName=="ClaimBase") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>ClaimBase");
                    }
                    global::Xtee.Core.SerializationMetadata metaClaimBase = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaimData>(Reader, "ClaimBase_ClaimData", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaimData item = metaClaimBase.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaimData>();
                    clazz.ClaimBase.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("ClaimBase");
                        metaClaimBase.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>ClaimBase", Reader.LocalName);
                }
            }
            if ((clazz.ClaimBase.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "ClaimBase");
            }
            if (Reader.LocalName=="PrincipalClaimsTotal") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>PrincipalClaimsTotal");
                }
                clazz.PrincipalClaimsTotal = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("PrincipalClaimsTotal")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>PrincipalClaimsTotal", Reader.LocalName);
            }
            if (Reader.LocalName=="CollateralClaimsTotal") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>CollateralClaimsTotal");
                }
                clazz.CollateralClaimsTotal = new global::Xtee.Core.Schema.XsdDecimal(Reader.ReadElementString("CollateralClaimsTotal")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>CollateralClaimsTotal", Reader.LocalName);
            }
            if (Reader.LocalName=="CircumstancesDescription") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>CircumstancesDescription");
                }
                clazz.CircumstancesDescription = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Description(Reader.ReadElementString("CircumstancesDescription"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>CircumstancesDescription", Reader.LocalName);
            }
            if (Reader.LocalName=="Currency") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>Currency");
                }
                clazz.Currency = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.Currency(Reader.ReadElementString("Currency"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>ClaimData>Currency", Reader.LocalName);
            }
            if (Reader.LocalName=="ClaimBase_Claim") {
                clazz.ClaimBaseClaim = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaim>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "ClaimBase_Claim")); ) {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ClaimData>ClaimBase_Claim");
                    }
                    global::Xtee.Core.SerializationMetadata metaClaimBaseClaim = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaim>(Reader, "ClaimBase_Claim", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaim item = metaClaimBaseClaim.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IClaimBaseClaim>();
                    clazz.ClaimBaseClaim.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("ClaimBase_Claim");
                        metaClaimBaseClaim.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
